function plot_AWQ_ObsTimeSeries(varname,site,data,depth,time_obs)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% TIMES SERIES PLOT OF OBSERVED PARAMETER 
%
% INPUT: - varname  : name as in awqparameters.xls  
%        - site     : name of AWQ site (string)
%        - data     : series of profile of AWQ weekly data (depth x date) 
%                     at a sinlge site  
%        - depth    : sampling depth
%        - time_obs : array of sampling dates (matlab format)
%
% EXAMPLE: 
%          load TestmatAWQ.mat
%          plot_AWQ_ObsTimeSeries('WaterTemp','B3',testmatAWQ.Tempts,...
%           testmatAWQ.Depthts,testmatAWQ.timets)
%
% Author: Benedicte Pasquer, IMOS/eMII (http://imos.org.au/)
% email: benedicte.pasquer@utas.edu.au
% May 2013   
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%CHECK IF VARNAME EXISTS
checkvarname(varname)
%CHECK WHETHER DATA IS EMPTY MATRIX
if isempty(data) | all(isnan(data))
    error('Dataset is empty');
end

% GET SURFACE AND BOTTOM VALUE OF A SINGLE PARAMETER   
valueS = get_value(data,depth,time_obs,'s');
valueB = get_value(data,depth,time_obs,'b');

%SPECIFY TIME TICK LABELS: EVERY 1ST OF JAN
year_minS = datevec(min(time_obs)) ;year_maxS = datevec(max(time_obs));
year_minS = datenum(year_minS(1),1,1); year_maxS = datenum(year_maxS(1)+1,1,1); 

datelabels = year_minS:366:year_maxS ;
[longname4labl,unit] = get_longname(varname);

diagname = sprintf('%s %s %s %s','Site ', site, ' - ', char(longname4labl));
titre{1} = diagname;
titre{2} ='surface and bottom concentration';


%DEFINE MAX VALUE FOR AXIS YLIM 

Ymax(1) = max(valueS);Ymax(2) = max(valueB);
Ymin(1) = min(valueS);Ymin(2) = min(valueB);

%DEFINE DATE RANGE FOR  XLIM : DATA UP TO 2008 ONLY

date4xlim = [731580 733775]; 

%FIGURE
figure('position',[1 1 1200 550],'Color',[.9 .98 .98])

hp1 = line(time_obs,valueS,'Marker','s','LineStyle','-','Linewidth',1);
hp2 = line(time_obs,valueB,'Marker','o','color','r','LineStyle','-','Linewidth',1);

hold on
%CALL TO PLOT ANZECC TRIGGER VALUES
plot_ANZECC;
hold off

%TITLE AND AXIS LABELLING
title(titre, ...
    'Fontname','arial','Fontsize',14,...
    'Fontweight','bold', ...
    'color',[0 0 .7]);
xlabel('Sampling date',...
    'Fontname','arial','Fontsize',14,...
    'Fontweight','bold',...
    'Color', [0 0 .7])

labl = [longname4labl{1} ' [' unit{1} ']']; 
ylabel(labl,'Fontname','arial',...
    'Fontsize',14,'Fontweight','bold',...
    'Color', [0 0 .7])

set (gca,'Fontsize',14,'Fontname' ,'Times','Fontweigh','bold',...
    'XLim',date4xlim,... 
    'Xtick',datelabels,...
    'YLim',[min(Ymin)*0.75 max(Ymax)*1.25],...
    'Color', [.9 .98 .98],'YColor', [0 0 .7], 'Xcolor', [0 0 .7], ...       
    'Fontname','arial','Fontsize',14,'Fontweight','bold',...
    'Position' , [0.11 0.19 0.785 0.70],...
    'Visible','on','Box','on')

%ADJUST YAXIS LIMITS TO THE DATA
if min(Ymin)*0.75 <10
 set(gca,'YLim',[0 max(Ymax)*1.25])
end

%LEGEND
if  exist('hl2','var')==0 && strcmp(varname,'Sal')==0 && strcmp(varname,'TotSuspSol')==0
     Dyn={'surface',...
        'bottom',...
        char('ANZECC', 'trigger level')};
    hleg = [hp1 hp2 hl1];
    lh = legend(hleg,Dyn{1:3},'Location','NorthEastOutside');
    
elseif strcmp(varname,'Salf')==1 || strcmp(varname,'TotSuspSols')==1
 % NO ANZECC REGULATION FOR SALINITY AND TOTAL SUSPENDED PARTICLES       
    lh=legend('surface','bottom','Location','NorthEastOutside');
    
else

    Dyn={'surface',...
    'bottom',...
    char('ANZECC triggers',' 95% protection'),...
    char('ANZECC triggers',' 80% protection')};
    hleg = [hp1 hp2 hl1 hl2];
    lh = legend(hleg,Dyn{1:4},'Location','NorthEastOutside');
    clear hl2
end

set(lh,'TextColor',[0 0 .7],...
    'Fontname','arial','Fontsize',14,'Fontweight','bold',...
    'box','off',...
    'color','none')

datetick('x','mmm-yyyy','keepticks','keeplimits')
hh = rotateXLabels(gca(),45);
set (hh,'Color',[0 0 .7])
set(gcf, 'InvertHardCopy', 'off');


figname = strcat(varname,'B&S',site);
outputfile = fullfile(pwd,varname,figname);
if ~exist(fullfile(pwd,varname),'dir');
    mkdir (fullfile(pwd,varname))
end

 saveas(gcf,outputfile,'png')
% close(gcf)

